﻿using HaiFengShop.Service;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;

namespace HaiFengShop.Controllers
{
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class SettingsController : ControllerBase
    {
        private readonly SettingsService settingsService;
        public SettingsController(SettingsService settingsService)
        {
            this.settingsService = settingsService;
        }

        /// <summary>
        /// 设置
        /// </summary> 
        [HttpGet]
        public IActionResult ShowSettings()
        {
            return Ok(settingsService.ShowSettings());
        }


        /// <summary>
        /// 获取用户个人信息
        /// </summary> 
        [HttpGet]
        public IActionResult UserDetail()
        {
            return Ok(settingsService.GetUserDetail());
        }

        /// <summary>
        /// 保存用户个人信息
        /// </summary> 
        [HttpPost]
        public IActionResult Save([FromBody]JObject postData)
        {
            string name = postData["name"].ToString();
            string mobile = postData["mobile"].ToString();
            return Ok(settingsService.SaveUserInfo(name, mobile));
        }
    }
}
